﻿@inject IDataCacheService _dataCacheService

<MDialog @bind-Value="Dialog"
         Width="800">
    <MDCard>
        <MCardTitle Class="text-h5">
            转载其他平台文章
        </MCardTitle>
        <MCardText Class="pb-0">
            目前只支持知乎、B站专栏文章
        </MCardText>
        <MStepper Value="_step" Vertical Elevation="0" Style="box-shadow: none;" Height="@("auto")">
            <MStepperStep Step="1" Complete="_step>1" >
                输入要转载的文章链接
            </MStepperStep>
            <MStepperContent Step="1">
                    <InputDataCard Model="Model" OnFinshInput="OnStart" />
            </MStepperContent>
            <MStepperStep Step="2" Complete="_step>2" >
                正在处理文章
            </MStepperStep>
            <MStepperContent Step="2">
                @if (_step == 2)
                {
                    <ProcCard Model="Model" @ref="procCard"  ArticleItems="ArticleItems" EntryGameItems="EntryGameItems"/>
                }
            </MStepperContent>
            <MStepperStep Step="3" Complete="_step>3" >
                文章处理完成
            </MStepperStep>
            <MStepperContent Step="3">
                <ResultCard Model="Model" OnRetry="OnRetry" />
            </MStepperContent>
        </MStepper>
    </MDCard>
</MDialog>
@code {
    private int _step = 1;
    bool Dialog { get; set; }

    public List<RepostArticleModel> Model { get; set; } = new List<RepostArticleModel>();
    private bool isReady = false;
    private IEnumerable<string> ArticleItems { get; set; } = new string[1] { "" };
    private IEnumerable<string> EntryGameItems { get; set; } = new string[1] { "" };

    ProcCard procCard;
    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            StateHasChanged();
        }
    }
   
    public async Task OnStart()
    {
        _step = 2;
        StateHasChanged();
        if (procCard != null)
        {
            await procCard.Proc();
        }
        _step = 3;
        StateHasChanged();
    }

    public async Task OnRetry()
    {
        _step = 1;
        StateHasChanged();
    }

    public async Task Refresh(bool dialog)
    {
        Dialog = dialog;

        StateHasChanged();
    }
}
